package com.justgame.project.generator.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.math.BigDecimal;

@Getter
public class Rule {

    private final RuleType ruleType;
    private final Object value;

    @Getter
    @RequiredArgsConstructor
    public enum RuleType{
        NOT_NULL(null),
        EMAIL(null),
        PHONE(null),
        HTTP_URL(null),
        IP(null),
        STR_LENGTH_MAX(Integer.class),
        STR_LENGTH_MIN(Integer.class),
        NUMBER_MAX(String.class),/* eg:"12.019","1.00" */
        NUMBER_MIN(String.class) /* eg:"12.019","1.00" */;
        final Class<?> valueClass;
    }

    public Rule(RuleType ruleType,Object value) {
        this.ruleType = ruleType;
        this.value = value;
    }

    public static Rule notNull(){
        return new Rule(RuleType.NOT_NULL,null);
    }

    public static Rule email(){
        return new Rule(RuleType.EMAIL,null);
    }

    public static Rule phone(){
        return new Rule(RuleType.PHONE,null);
    }

    public static Rule httpUrl(){
        return new Rule(RuleType.HTTP_URL,null);
    }

    public static Rule IP(){
        return new Rule(RuleType.IP,null);
    }

    public static Rule maxLength(Integer num){
        return new Rule(RuleType.STR_LENGTH_MAX, num);
    }

    public static Rule minLength(Integer num){
        return new Rule(RuleType.STR_LENGTH_MIN, num);
    }

    public static Rule maxNumber(BigDecimal num){
        return new Rule(RuleType.NUMBER_MAX, num.toString());
    }

    public static Rule minNumber(BigDecimal num){
        return new Rule(RuleType.NUMBER_MIN, num.toString());
    }
}
